package com.coda.app.controller;

import com.coda.app.service.RegionService;
import com.coda.entity.CityInfo;
import com.coda.entity.DistrictInfo;
import com.coda.entity.ProvinceInfo;
import com.coda.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/app/region")
@Api(tags = "地区信息")
public class RegionController {

    @Autowired
    private RegionService regionService;

    /**
     * 查询省份列表
     */
    @GetMapping("/province/list")
    @ApiOperation("查询省份信息列表")
    public Result<List<ProvinceInfo>> listProvinceInfo() {
        List<ProvinceInfo> provinceInfoList = regionService.getProvince();
        return Result.ok(provinceInfoList);
    }

    /**
     * 根据省份id查询城市列表
     */
    @GetMapping("/city/listByProvinceId")
    @ApiOperation("根据省份id查询城市列表")
    public Result<List<CityInfo>> getCityList(@RequestParam Long id) {
        List<CityInfo> cityInfoList = regionService.getCityList(id);
        return Result.ok(cityInfoList);
    }
    /**
     * 根据城市id查询县区列表
     */
    @GetMapping("/district/listByCityId")
    @ApiOperation("根据城市id查询县区列表")
    public Result<List<DistrictInfo>> getDistrictList(@RequestParam Long id){
        List<DistrictInfo> districtInfoList = regionService.getDistrictList(id);
        return Result.ok(districtInfoList);
    }

}
